﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace CalculatorMVVM.Command
{
    public delegate void executeDelegate();
    public delegate bool canExecuteDelegate();

    class RelayCommand: ICommand
    {
        private executeDelegate execute;
        private canExecuteDelegate canExecuteDelegate;
        public event EventHandler CanExecuteChanged;

        public RelayCommand(executeDelegate execute, canExecuteDelegate canExecuteDelegate=null)
        {
            this.execute = execute;
            this.canExecuteDelegate = canExecuteDelegate;
        }

        public bool CanExecute(object parameter)
        {
            if (canExecuteDelegate == null)
            {
                return true;
            }

            return this.canExecuteDelegate();
        }

        

        public void Execute(object parameter)
        {
            this.execute();
        }
    }
}
